<template>
  <div>
    <el-form :model="loginForm">
      <el-form-item label="账号">
        <el-input v-model="loginForm.account" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="loginForm.password" />
      </el-form-item>
      <el-button @click="loginFormSubmit">登录</el-button>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
import { useUserStore } from '@/store/user'
import { IUserLoginOption } from '@/service/api/login/types'
import { reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { passwordCheck } from '@/utils/rules'
const userStore = useUserStore()
const loginForm: IUserLoginOption = reactive({
  account: '',
  password: '',
})
function loginFormSubmit() {
  if (loginForm.account === '') {
    ElMessage({
      type: 'warning',
      message: '请填写账号',
    })
    return false
  }
  if (!passwordCheck(loginForm.password)) {
    ElMessage({
      type: 'warning',
      message: '请正确填写密码',
    })
    return false
  }
  userStore.userLogin(loginForm)
}
</script>
